{% extends 'rebs/layouts/base.html' %}

{% block title %}Rebs - Company List{% endblock %}

{% block content %}
    {% load static humanize widget_tweaks %}

    <!-- Start Content-->
    <div class="container-fluid">

        <!-- start page title -->
        {% include 'rebs/partials/content_title.html' with  second_bs="환경 설정" title="회사 정보" %}
        <!-- end page title -->

        <div class="row">
            <form class="form-horizontal p-0 col-12" method="get">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">

                            {% with menu_order='1' %}
                                {% include 'rebs_company/partials/head_menu.html' %}
                            {% endwith %}

                            <div class="row">
                                {% include 'rebs_company/partials/company_list.html' %}
                                <div class="col-sm-12 col-md-6"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

            {% if request.GET.id %}
                <form method="post" class="col-12 form-row needs-validation" novalidate>
                    {% csrf_token %}
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group row mb-3 col-12 position-relative">
                                        <label for="{{ form.name.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.name.label }}</label>
                                        <div class="col-9">
                                            {{ form.name|add_class:"form-control"|attr:"placeholder:회사명" }}
                                            <div class="invalid-tooltip">{{ form.name.label }}을 입력하세요.</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.ceo.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.ceo.label }}</label>
                                        <div class="col-9">
                                            {{ form.ceo|add_class:"form-control"|attr:"placeholder:대표자명" }}
                                            <div class="invalid-tooltip">{{ form.ceo.label }}을 입력하세요.</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.business_cond.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.business_cond.label }}</label>
                                        <div class="col-9">
                                            {{ form.business_cond|add_class:"form-control"|attr:"placeholder:업태" }}
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.es_date.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.es_date.label }}</label>
                                        <div class="col-9">
                                            {{ form.es_date|add_class:"form-control"|attr:"placeholder:설립일자"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00" }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.tax_number.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.tax_number.label }}</label>
                                        <div class="col-9">
                                            {{ form.tax_number|add_class:"form-control"|attr:"placeholder:사업자등록번호"|attr:"data-toggle=input-mask data-mask-format=000-00-00000" }}
                                            <div class="invalid-tooltip">{{ form.tax_number.label }}을 입력하세요.</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.org_number.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.org_number.label }}</label>
                                        <div class="col-9">
                                            {{ form.org_number|add_class:"form-control"|attr:"placeholder:법인등록번호"|attr:"data-toggle=input-mask data-mask-format=000000-0000000" }}
                                            <div class="invalid-tooltip">{{ form.org_number.label }}을 입력하세요.</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.business_even.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.business_even.label }}</label>
                                        <div class="col-9">
                                            {{ form.business_even|add_class:"form-control"|attr:"placeholder:종목" }}
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.op_date.id_for_label }}"
                                               class="col-3 col-form-label">{{ form.op_date.label }}</label>
                                        <div class="col-9">
                                            {{ form.op_date|add_class:"form-control"|attr:"placeholder:개업일자"|attr:"data-provide=datepicker data-date-format=yyyy-mm-dd data-date-autoclose=true data-toggle=input-mask data-mask-format=0000-00-00" }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-row col-12">
                                        <div class="form-group col-md-6 col-lg-2 col-xl-1">
                                            <label for="" class="col-form-label">회사 주소</label>
                                            {{ form.zipcode|add_class:"form-control"|attr:"placeholder:우편번호"|attr:"readonly"|attr:"onclick=sample2_execDaumPostcode('id_')" }}
                                        </div>
                                        <div class="form-group col-md-6 col-lg-2 col-xl-1">
                                            <label for="" class="col-form-label d-none d-md-block">&nbsp;</label>
                                            <input type="button" class="btn btn-info form-control" value="우편번호"
                                                   onclick="sample2_execDaumPostcode('id_')">
                                        </div>
                                        <div class="form-group col-md-12 col-lg-8 col-xl-9"></div>
                                    </div>
                                    <div class="form-row col-12">
                                        <div class="form-group col-md-12 col-xl-6">
                                            {{ form.address1|add_class:"form-control"|attr:"placeholder:시, 도, 구(군)"|attr:"onclick=sample2_execDaumPostcode('id_')" }}
                                        </div>
                                        <div class="form-group col-md-6 col-xl-3">
                                            {{ form.address2|add_class:"form-control"|attr:"placeholder:상세주소" }}
                                        </div>
                                        <div class="form-group col-md-6 col-xl-3">
                                            {{ form.address3|add_class:"form-control"|attr:"placeholder:참고항목" }}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group mb-0 justify-content-end row">
                                        <div class="col-12">
                                            <button type="button" class="btn btn-light" onclick="location.href='{% url 'rebs:company:index' %}'">취소하기</button>&nbsp;
                                            <button type="submit" class="btn btn-success">수정하기</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            {% else %}
                {% for company in object_list %}
                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="row mb-3 col-12">
                                        <label for="{{ form.name.id_for_label }}"
                                               class="col-3 col-form-label bg-light">회사명</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3">{{ company.name }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.ceo.id_for_label }}"
                                               class="col-3 col-form-label bg-light">대표자명</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.ceo }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.business_cond.id_for_label }}"
                                               class="col-3 col-form-label bg-light">업태</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.business_cond }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.es_date.id_for_label }}"
                                               class="col-3 col-form-label bg-light">설립일자</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.es_date }}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-6">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">

                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.tax_number.id_for_label }}"
                                               class="col-3 col-form-label bg-light">사업자등록번호</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.tax_number }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.org_number.id_for_label }}"
                                               class="col-3 col-form-label bg-light">법인등록번호</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.org_number }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.business_even.id_for_label }}"
                                               class="col-3 col-form-label bg-light">종목</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">{{ company.business_even }}</div>
                                        </div>
                                    </div>
                                    <div class="form-group row mb-3 col-12">
                                        <label for="{{ form.op_date.id_for_label }}"
                                               class="col-3 col-form-label bg-light">개업일자</label>
                                        <div class="col-9">
                                            <div class="col-form-labe text-black-50l pl-3"">{{ company.op_date }}</div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group row mb-3 col-lg-6">
                                        <label for="{{ form.op_date.id_for_label }}"
                                               class="col-3 col-form-label bg-light">회사주소</label>
                                        <div class="col-9">
                                            <div class="col-form-label text-black-50 pl-3"">
                                                {{ company.zipcode }} {{ company.address1 }} {{ company.address2 }} {{ company.address3 }}
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group mb-0 justify-content-end row">
                                        <div class="col-12">
                                            {% if request.user.is_superuser or request.user.staffauth.company_cash > '1' %}
                                                <button class="btn btn-success"
                                                    onclick=location.href="{% url 'rebs:company:index' %}?id={{ company.id }}">
                                                    수정하기
                                                </button>
                                            {% else %}
                                                <button type="button" class="btn btn-outline-secondary"
                                                        onclick="alert('입출금 내역 등록 권한이 없습니다. 관리자에게 문의하여 주십시요.')">조회권한 사용자
                                                </button>
                                            {% endif %}
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% endfor %}

                {% if not object_list %}
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group mb-0 row">
                                        <div class="col-12 m-5 text-danger justify-content-center">
                                            등록된 회사 정보가 없습니다.
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">
                                <div class="row">
                                    <div class="form-group mb-0 justify-content-end row">
                                        <div class="col-12">
                                            <button class="btn btn-outline-primary"
                                                    onclick=location.href="{% url 'rebs:company:create' %}">
                                                신규등록
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                {% endif %}
            {% endif %}
        </div>

    </div> <!-- container -->
{% endblock %}
